import subprocess
import time
import allure
import pytest

def run_with_pytest_html_report():
    """
    使用pytest_html报告
    :param project_name:
    :return:
    """
    tmp = time.strftime("%Y%m%d_%H%M%S", time.localtime(time.time()))
    pytest.main(['-s','-v',f'--html=reports/{tmp}.html','--self-contained-html'])

def run_with_allure_report():
    """
    生成allure报告
    :param project_name:
    :return:
    """
    reportsdir = f'reports/{time.strftime("%Y%m%d_%H%M%S", time.localtime(time.time()))}'
    pytest.main(['-s','-v',f'--alluredir={reportsdir}'])
    # subprocess.call(f'allure.bat serve {reportsdir}', shell=True)
    # 终端执行命令也可以直接打开
    # allure.bat serve reports/20230508_111808
    # subprocess.call(f'allure generate {reportsdir} -o {reportsdir}.html',shell=True)zuiha

if __name__ == '__main__':
    run_with_allure_report()
    print("我是刘江写的")
